/**
* Created by wust on 2019/5/16.
*/
<template xmlns:v-data-dictionary-directive="http://www.w3.org/1999/xhtml">
  <el-form ref="updateModel" :model="updateModel" :rules="rules" label-width="120px" style="width:70%;" @submit.native.prevent>
    <el-form-item label="公司编码">
      <el-input
        v-model="updateModel.code"
        :disabled="true">
      </el-input>
    </el-form-item>
    <el-form-item label="公司名" prop="name">
      <el-input v-model="updateModel.name"></el-input>
    </el-form-item>
    <el-form-item label="备注">
      <el-input
              v-model="updateModel.description"
              type="textarea"
              :rows="6">
      </el-input>
    </el-form-item>
    <el-form-item style="text-align: left;">
      <el-button type="primary" @click="onSubmit('updateModel')" :loading="submitting">提交</el-button>
    </el-form-item>
  </el-form>
</template>
<script>
import Vue from 'vue'

export default {
  name: 'company-update',
  props: ['selectedModel'],
  data () {
    return {
      submitting: false,
      updateModel: {
        name: '',
        description: ''
      },
      rules: {
        name: [{required: true, message: '请输入公司名称', trigger: 'blur'}]
      }
    }
  },
  created: function () {
    this.updateModel = this.selectedModel
  },
  methods: {
    onSubmit: function (formData) {
      this.$refs[formData].validate((valid) => {
        if (!valid) {
        } else {
          this.submitting = true
          Vue.$ajax({
            method: 'put',
            url: Vue.$adminServerURL + '/web/v1/CompanyController',
            data: this.updateModel
          }).then(res => {
            this.submitting = false
            if (res.data.flag !== 'SUCCESS') {
              if (!Vue.$isNullOrIsBlankOrIsUndefined(res.data.message)) {
                this.$message({
                  message: res.data.message,
                  type: 'warning'
                })
              }
            } else {
              this.$message({
                message: res.data.message,
                type: 'success'
              })
            }
          })
        }
      })
    }
  }
}
</script>
